home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / source.exe / POSIX / BSDPSX / POSIXDBG.C < prev    next >
C/C++ Source or Header  |  1992-08-14  |  62KB  |  2,259 lines

  1. /*
  2.     posixdbg.c
  3.  
  4.     POSIX debugging for those of us without debugging gear
  5. */
  6.  
  7. #include <string.h>
  8. #include <errno.h>
  9. #include <unistd.h>
  10. #include <stdarg.h>
  11. #include <sys/wait.h>
  12. #include <signal.h>
  13. #include <sys/utsname.h>
  14. #include <time.h>
  15. #include <sys/times.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <dirent.h>
  19. #include <fcntl.h>
  20. #include <sys/stat.h>
  21. #include <utime.h>
  22. #include <termios.h>
  23. #include <setjmp.h>
  24. #include <grp.h>
  25. #include <pwd.h>
  26.  
  27. #define NARGS 16 /* maximum number of arguments for execl* calls (for display purposes) */
  28. #define NENVS 32 /* maximum number of environment variables for execle call (for display purposes) */
  29.  
  30. struct sigmap {
  31.     int signum;
  32.     const char *signame;
  33. };
  34.  
  35. struct howmap {
  36.     int hownum;
  37.     const char *howname;
  38. };
  39.  
  40. struct scnamemap {
  41.     int scnamenum;
  42.     const char *scnamename;
  43. };
  44.  
  45. struct pcnamemap {
  46.     int pcnamenum;
  47.     const char *pcnamename;
  48. };
  49.  
  50. struct cmdmap {
  51.     int cmdnum;
  52.     const char *cmdname;
  53. };
  54.  
  55. struct whencemap {
  56.     int whencenum;
  57.     const char *whencename;
  58. };
  59.  
  60. struct speedmap {
  61.     speed_t speednum;
  62.     const char *speedname;
  63. };
  64.  
  65. struct optactmap {
  66.     int optactnum;
  67.     const char *optactname;
  68. };
  69.  
  70. struct queuemap {
  71.     int queuenum;
  72.     const char *queuename;
  73. };
  74.  
  75. struct actionmap {
  76.     int actionnum;
  77.     const char *actionname;
  78. };
  79.  
  80. static const char *canonical_string (const char *string)
  81. {
  82.     static const char null[] = "NULL";
  83.     static char buf[BUFSIZ];
  84.     const char *ret;
  85.  
  86.     if (string == NULL)
  87.         ret = null;
  88.     else
  89.     {
  90.         (void) sprintf(buf, "\"%s\"", string);
  91.         ret = (const char *) buf;
  92.     }
  93.     return ret;
  94. }
  95.  
  96. char *options_string (int waitpid_options)
  97. {
  98.     static const char bitwise_or[] = "|";
  99.     static char buf[BUFSIZ];
  100.     char integer_string[11];
  101.  
  102.     *buf = '\0';
  103.     if (waitpid_options & WNOHANG)
  104.     {
  105.         (void) strcat(buf, "WNOHANG");
  106.         waitpid_options &= ~WNOHANG;
  107.     }
  108.     if (waitpid_options & WUNTRACED)
  109.     {
  110.         if (*buf != '\0')
  111.             (void) strcat(buf, bitwise_or);
  112.         (void) strcat(buf, "WUNTRACED");
  113.         waitpid_options &= ~WUNTRACED;
  114.     }
  115.     if (waitpid_options)
  116.     {
  117.         if (*buf != '\0')
  118.             (void) strcat(buf, bitwise_or);
  119.         (void) sprintf(integer_string, "%#08X", (unsigned int) waitpid_options);
  120.         (void) strcat(buf, integer_string);
  121.     }
  122.     return buf;
  123. }
  124.  
  125. char *signum_string (int function_signum)
  126. {
  127.     static const struct sigmap sigtable[] = {
  128.         { SIGABRT, "SIGABRT" }, { SIGALRM, "SIGALRM" }, { SIGFPE,  "SIGFPE"  }, { SIGHUP,  "SIGHUP"  },
  129.         { SIGILL,  "SIGILL"  }, { SIGINT,  "SIGINT"  }, { SIGKILL, "SIGKILL" }, { SIGPIPE, "SIGPIPE" },
  130.         { SIGQUIT, "SIGQUIT" }, { SIGSEGV, "SIGSEGV" }, { SIGTERM, "SIGTERM" }, { SIGUSR1, "SIGUSR1" },
  131.         { SIGUSR2, "SIGUSR2" }, { SIGCHLD, "SIGCHLD" }, { SIGCONT, "SIGCONT" }, { SIGSTOP, "SIGSTOP" },
  132.         { SIGTSTP, "SIGTSTP" }, { SIGTTIN, "SIGTTIN" }, { SIGTTOU, "SIGTTOU" }, { 0,       NULL      }
  133.     };
  134.     static char buf[BUFSIZ];
  135.     const struct sigmap *sigtblptr;
  136.  
  137.     for (sigtblptr = sigtable; sigtblptr->signum != 0; ++sigtblptr)
  138.         if (sigtblptr->signum == function_signum)
  139.             break;
  140.     if (sigtblptr->signum == 0)
  141.         (void) sprintf(buf, "%d", function_signum);
  142.     else
  143.         (void) strcpy(buf, sigtblptr->signame);
  144.     return buf;
  145. }
  146.  
  147. char *how_string (int sigprocmask_how)
  148. {
  149.     static const struct howmap howtable[] = {
  150.         { SIG_BLOCK,   "SIG_BLOCK"   }, { SIG_UNBLOCK, "SIG_UNBLOCK" }, { SIG_SETMASK, "SIG_SETMASK" },
  151.         { 0,           NULL          }
  152.     };
  153.     static char buf[BUFSIZ];
  154.     const struct howmap *howtblptr;
  155.  
  156.     for (howtblptr = howtable; howtblptr->hownum != 0; ++howtblptr)
  157.         if (howtblptr->hownum == sigprocmask_how)
  158.             break;
  159.     if (howtblptr->hownum == 0)
  160.         (void) sprintf(buf, "%d", sigprocmask_how);
  161.     else
  162.         (void) strcpy(buf, howtblptr->howname);
  163.     return buf;
  164. }
  165.  
  166. char *scname_string (int sysconf_name)
  167. {
  168.     static const struct scnamemap scnametable[] = {
  169.         { _SC_ARG_MAX,     "_SC_ARG_MAX"     }, { _SC_CHILD_MAX,   "_SC_CHILD_MAX"   },
  170.         { _SC_CLK_TCK,     "_SC_CLK_TCK"     }, { _SC_NGROUPS_MAX, "_SC_NGROUPS_MAX" },
  171.         { _SC_OPEN_MAX,    "_SC_OPEN_MAX"    }, { _SC_STREAM_MAX,  "_SC_STREAM_MAX"  },
  172.         { _SC_TZNAME_MAX,  "_SC_TZNAME_MAX"  }, { _SC_JOB_CONTROL, "_SC_JOB_CONTROL" },
  173.         { _SC_SAVED_IDS,   "_SC_SAVED_IDS"   }, { _SC_VERSION,     "_SC_VERSION"     },
  174.         { 0,               NULL              }
  175.     };
  176.     static char buf[BUFSIZ];
  177.     const struct scnamemap *scnametblptr;
  178.  
  179.     for (scnametblptr = scnametable; scnametblptr->scnamenum != 0; ++scnametblptr)
  180.         if (scnametblptr->scnamenum == sysconf_name)
  181.             break;
  182.     if (scnametblptr->scnamenum == 0)
  183.         (void) sprintf(buf, "%d", sysconf_name);
  184.     else
  185.         (void) strcpy(buf, scnametblptr->scnamename);
  186.     return buf;
  187. }
  188.  
  189. char *oflag_string (int open_oflag)
  190. {
  191.     static const char bitwise_or[] = "|";
  192.     static char buf[BUFSIZ];
  193.     char integer_string[11];
  194.  
  195.     *buf = '\0';
  196.     if ((open_oflag & O_ACCMODE) == O_RDONLY)
  197.     {
  198.         (void) strcat(buf, "O_RDONLY");
  199.         open_oflag &= ~O_ACCMODE;
  200.     }
  201.     else if ((open_oflag & O_ACCMODE) == O_WRONLY)
  202.     {
  203.         (void) strcat(buf, "O_WRONLY");
  204.         open_oflag &= ~O_ACCMODE;
  205.     }
  206.     else if ((open_oflag & O_ACCMODE) == O_RDWR)
  207.     {
  208.         (void) strcat(buf, "O_RDWR");
  209.         open_oflag &= ~O_ACCMODE;
  210.     }
  211.     if (open_oflag & O_APPEND)
  212.     {
  213.         if (*buf != '\0')
  214.             (void) strcat(buf, bitwise_or);
  215.         (void) strcat(buf, "O_APPEND");
  216.         open_oflag &= ~O_APPEND;
  217.     }
  218.     if (open_oflag & O_CREAT)
  219.     {
  220.         if (*buf != '\0')
  221.             (void) strcat(buf, bitwise_or);
  222.         (void) strcat(buf, "O_CREAT");
  223.         open_oflag &= ~O_CREAT;
  224.     }
  225.     if (open_oflag & O_EXCL)
  226.     {
  227.         if (*buf != '\0')
  228.             (void) strcat(buf, bitwise_or);
  229.         (void) strcat(buf, "O_EXCL");
  230.         open_oflag &= ~O_EXCL;
  231.     }
  232.     if (open_oflag & O_NOCTTY)
  233.     {
  234.         if (*buf != '\0')
  235.             (void) strcat(buf, bitwise_or);
  236.         (void) strcat(buf, "O_NOCTTY");
  237.         open_oflag &= ~O_NOCTTY;
  238.     }
  239.     if (open_oflag & O_NONBLOCK)
  240.     {
  241.         if (*buf != '\0')
  242.             (void) strcat(buf, bitwise_or);
  243.         (void) strcat(buf, "O_NONBLOCK");
  244.         open_oflag &= ~O_NONBLOCK;
  245.     }
  246.     if (open_oflag & O_TRUNC)
  247.     {
  248.         if (*buf != '\0')
  249.             (void) strcat(buf, bitwise_or);
  250.         (void) strcat(buf, "O_TRUNC");
  251.         open_oflag &= ~O_TRUNC;
  252.     }
  253.     if (open_oflag)
  254.     {
  255.         if (*buf != '\0')
  256.             (void) strcat(buf, bitwise_or);
  257.         (void) sprintf(integer_string, "%#08X", (unsigned int) open_oflag);
  258.         (void) strcat(buf, integer_string);
  259.     }
  260.     return buf;
  261. }
  262.  
  263. char *mode_string (mode_t function_mode)
  264. {
  265.     static const char bitwise_or[] = "|";
  266.     static char buf[BUFSIZ];
  267.     char mode_t_string[13];
  268.  
  269.     *buf = '\0';
  270.     if (function_mode & S_IRUSR)
  271.     {
  272.         (void) strcat(buf, "S_IRUSR");
  273.         function_mode &= ~S_IRUSR;
  274.     }
  275.     if (function_mode & S_IWUSR)
  276.     {
  277.         if (*buf != '\0')
  278.             (void) strcat(buf, bitwise_or);
  279.         (void) strcat(buf, "S_IWUSR");
  280.         function_mode &= ~S_IWUSR;
  281.     }
  282.     if (function_mode & S_IXUSR)
  283.     {
  284.         if (*buf != '\0')
  285.             (void) strcat(buf, bitwise_or);
  286.         (void) strcat(buf, "S_IXUSR");
  287.         function_mode &= ~S_IXUSR;
  288.     }
  289.     if (function_mode & S_IRGRP)
  290.     {
  291.         if (*buf != '\0')
  292.             (void) strcat(buf, bitwise_or);
  293.         (void) strcat(buf, "S_IRGRP");
  294.         function_mode &= ~S_IRGRP;
  295.     }
  296.     if (function_mode & S_IWGRP)
  297.     {
  298.         if (*buf != '\0')
  299.             (void) strcat(buf, bitwise_or);
  300.         (void) strcat(buf, "S_IWGRP");
  301.         function_mode &= ~S_IWGRP;
  302.     }
  303.     if (function_mode & S_IXGRP)
  304.     {
  305.         if (*buf != '\0')
  306.             (void) strcat(buf, bitwise_or);
  307.         (void) strcat(buf, "S_IXGRP");
  308.         function_mode &= ~S_IXGRP;
  309.     }
  310.     if (function_mode & S_IROTH)
  311.     {
  312.         if (*buf != '\0')
  313.             (void) strcat(buf, bitwise_or);
  314.         (void) strcat(buf, "S_IROTH");
  315.         function_mode &= ~S_IROTH;
  316.     }
  317.     if (function_mode & S_IWOTH)
  318.     {
  319.         if (*buf != '\0')
  320.             (void) strcat(buf, bitwise_or);
  321.         (void) strcat(buf, "S_IWOTH");
  322.         function_mode &= ~S_IWOTH;
  323.     }
  324.     if (function_mode & S_IXOTH)
  325.     {
  326.         if (*buf != '\0')
  327.             (void) strcat(buf, bitwise_or);
  328.         (void) strcat(buf, "S_IXOTH");
  329.         function_mode &= ~S_IXOTH;
  330.     }
  331.     if (function_mode & S_ISUID)
  332.     {
  333.         if (*buf != '\0')
  334.             (void) strcat(buf, bitwise_or);
  335.         (void) strcat(buf, "S_ISUID");
  336.         function_mode &= ~S_ISUID;
  337.     }
  338.     if (function_mode & S_ISGID)
  339.     {
  340.         if (*buf != '\0')
  341.             (void) strcat(buf, bitwise_or);
  342.         (void) strcat(buf, "S_ISGID");
  343.         function_mode &= ~S_ISGID;
  344.     }
  345.     if (function_mode)
  346.     {
  347.         if (*buf != '\0')
  348.             (void) strcat(buf, bitwise_or);
  349.         (void) sprintf(mode_t_string, "%#11lo", (unsigned long) function_mode);
  350.         (void) strcat(buf, mode_t_string);
  351.     }
  352.     return buf;
  353. }
  354.  
  355. char *amode_string (int access_amode)
  356. {
  357.     static const char bitwise_or[] = "|";
  358.     static char buf[BUFSIZ];
  359.     char integer_string[11];
  360.  
  361.     *buf = '\0';
  362.     if (access_amode == F_OK)
  363.     {
  364.         (void) strcat(buf, "F_OK");
  365.         access_amode &= ~F_OK;
  366.     }
  367.     else
  368.     {
  369.         if (access_amode & R_OK)
  370.         {
  371.             (void) strcat(buf, "R_OK");
  372.             access_amode &= ~R_OK;
  373.         }
  374.         if (access_amode & W_OK)
  375.         {
  376.             if (*buf != '\0')
  377.                 (void) strcat(buf, bitwise_or);
  378.             (void) strcat(buf, "W_OK");
  379.             access_amode &= ~W_OK;
  380.         }
  381.         if (access_amode & X_OK)
  382.         {
  383.             if (*buf != '\0')
  384.                 (void) strcat(buf, bitwise_or);
  385.             (void) strcat(buf, "X_OK");
  386.             access_amode &= ~X_OK;
  387.         }
  388.     }
  389.     if (access_amode)
  390.     {
  391.         if (*buf != '\0')
  392.             (void) strcat(buf, bitwise_or);
  393.         (void) sprintf(integer_string, "%#08X", (unsigned int) access_amode);
  394.         (void) strcat(buf, integer_string);
  395.     }
  396.     return buf;
  397. }
  398.  
  399. char *pcname_string (int function_name)
  400. {
  401.     static const struct pcnamemap pcnametable[] = {
  402.         { _PC_LINK_MAX,         "_PC_LINK_MAX"         }, { _PC_MAX_CANON,        "_PC_MAX_CANON"        },
  403.         { _PC_MAX_INPUT,        "_PC_MAX_INPUT"        }, { _PC_NAME_MAX,         "_PC_NAME_MAX"         },
  404.         { _PC_PATH_MAX,         "_PC_PATH_MAX"         }, { _PC_PIPE_BUF,         "_PC_PIPE_BUF"         },
  405.         { _PC_CHOWN_RESTRICTED, "_PC_CHOWN_RESTRICTED" }, { _PC_NO_TRUNC,         "_PC_NO_TRUNC"         },
  406.         { _PC_VDISABLE,         "_PC_VDISABLE"         }, { 0,                    NULL                   }
  407.     };
  408.     static char buf[BUFSIZ];
  409.     const struct pcnamemap *pcnametblptr;
  410.  
  411.     for (pcnametblptr = pcnametable; pcnametblptr->pcnamenum != 0; ++pcnametblptr)
  412.         if (pcnametblptr->pcnamenum == function_name)
  413.             break;
  414.     if (pcnametblptr->pcnamenum == 0)
  415.         (void) sprintf(buf, "%d", function_name);
  416.     else
  417.         (void) strcpy(buf, pcnametblptr->pcnamename);
  418.     return buf;
  419. }
  420.  
  421. char *cmd_string (int fcntl_cmd)
  422. {
  423.     static const struct cmdmap cmdtable[] = {
  424.         { F_DUPFD,  "F_DUPFD"  }, { F_GETFD,  "F_GETFD"  }, { F_SETFD,  "F_SETFD"  }, { F_GETFL,  "F_GETFL"  },
  425.         { F_SETFL,  "F_SETFL"  }, { F_GETLK,  "F_GETLK"  }, { F_SETLK,  "F_SETLK"  }, { F_SETLKW, "F_SETLKW" },
  426.         { 0,        NULL       }
  427.     };
  428.     static char buf[BUFSIZ];
  429.     const struct cmdmap *cmdtblptr;
  430.  
  431.     for (cmdtblptr = cmdtable; cmdtblptr->cmdnum != 0; ++cmdtblptr)
  432.         if (cmdtblptr->cmdnum == fcntl_cmd)
  433.             break;
  434.     if (cmdtblptr->cmdnum == 0)
  435.         (void) sprintf(buf, "%d", fcntl_cmd);
  436.     else
  437.         (void) strcpy(buf, cmdtblptr->cmdname);
  438.     return buf;
  439. }
  440.  
  441. char *whence_string (int lseek_whence)
  442. {
  443.     static const struct whencemap whencetable[] = {
  444.         { SEEK_SET, "SEEK_SET" }, { SEEK_CUR, "SEEK_CUR" }, { SEEK_END, "SEEK_END" }, { 0,        NULL       }
  445.     };
  446.     static char buf[BUFSIZ];
  447.     const struct whencemap *whencetblptr;
  448.  
  449.     for (whencetblptr = whencetable; whencetblptr->whencenum != 0; ++whencetblptr)
  450.         if (whencetblptr->whencenum == lseek_whence)
  451.             break;
  452.     if (whencetblptr->whencenum == 0)
  453.         (void) sprintf(buf, "%d", lseek_whence);
  454.     else
  455.         (void) strcpy(buf, whencetblptr->whencename);
  456.     return buf;
  457. }
  458.  
  459. char *speed_string (speed_t function_speed)
  460. {
  461.     static const struct speedmap speedtable[] = {
  462.         { B0,     "B0"     }, { B50,    "B50"    }, { B75,    "B75"    }, { B110,   "B110"   }, { B134,   "B134"   },
  463.         { B150,   "B150"   }, { B200,   "B200"   }, { B300,   "B300"   }, { B600,   "B600"   }, { B1200,  "B1200"  },
  464.         { B1800,  "B1800"  }, { B2400,  "B2400"  }, { B4800,  "B4800"  }, { B9600,  "B9600"  }, { B19200, "B19200" },
  465.         { B38400, "B38400" }, { 0,      NULL     }
  466.     };
  467.     static char buf[BUFSIZ];
  468.     const struct speedmap *speedtblptr;
  469.  
  470.     for (speedtblptr = speedtable; speedtblptr->speednum != 0; ++speedtblptr)
  471.         if (speedtblptr->speednum == function_speed)
  472.             break;
  473.     if (speedtblptr->speednum == 0)
  474.         (void) sprintf(buf, "%d", function_speed);
  475.     else
  476.         (void) strcpy(buf, speedtblptr->speedname);
  477.     return buf;
  478. }
  479.  
  480. char *optact_string (int tcsetattr_optact)
  481. {
  482.     static const struct optactmap optacttable[] = {
  483.         { TCSANOW,   "TCSANOW"   }, { TCSADRAIN, "TCSADRAIN" }, { TCSAFLUSH, "TCSAFLUSH" }, { 0,         NULL        }
  484.     };
  485.     static char buf[BUFSIZ];
  486.     const struct optactmap *optacttblptr;
  487.  
  488.     for (optacttblptr = optacttable; optacttblptr->optactnum != 0; ++optacttblptr)
  489.         if (optacttblptr->optactnum == tcsetattr_optact)
  490.             break;
  491.     if (optacttblptr->optactnum == 0)
  492.         (void) sprintf(buf, "%d", tcsetattr_optact);
  493.     else
  494.         (void) strcpy(buf, optacttblptr->optactname);
  495.     return buf;
  496. }
  497.  
  498. char *queue_string (int tcflush_queue)
  499. {
  500.     static const struct queuemap queuetable[] = {
  501.         { TCIFLUSH,  "TCIFLUSH"  }, { TCOFLUSH,  "TCOFLUSH"  }, { TCIOFLUSH, "TCIOFLUSH" }, { 0,         NULL        }
  502.     };
  503.     static char buf[BUFSIZ];
  504.     const struct queuemap *queuetblptr;
  505.  
  506.     for (queuetblptr = queuetable; queuetblptr->queuenum != 0; ++queuetblptr)
  507.         if (queuetblptr->queuenum == tcflush_queue)
  508.             break;
  509.     if (queuetblptr->queuenum == 0)
  510.         (void) sprintf(buf, "%d", tcflush_queue);
  511.     else
  512.         (void) strcpy(buf, queuetblptr->queuename);
  513.     return buf;
  514. }
  515.  
  516. char *action_string (int tcflow_action)
  517. {
  518.     static const struct actionmap actiontable[] = {
  519.         { TCOOFF, "TCOOFF" }, { TCOON,  "TCOON"  }, { TCIOFF, "TCIOFF" }, { TCION,  "TCION"  }, { 0,      NULL     }
  520.     };
  521.     static char buf[BUFSIZ];
  522.     const struct actionmap *actiontblptr;
  523.  
  524.     for (actiontblptr = actiontable; actiontblptr->actionnum != 0; ++actiontblptr)
  525.         if (actiontblptr->actionnum == tcflow_action)
  526.             break;
  527.     if (actiontblptr->actionnum == 0)
  528.         (void) sprintf(buf, "%d", tcflow_action);
  529.     else
  530.         (void) strcpy(buf, actiontblptr->actionname);
  531.     return buf;
  532. }
  533.  
  534. /* Section 3: Process Primitives */
  535.  
  536. pid_t posix_debug_fork (void)
  537. {
  538.     pid_t ret;
  539.     int err;
  540.  
  541.     (void) fprintf(stderr, "entering fork()\n");
  542.     (void) fflush(stderr);
  543.     ret = fork();
  544.     err = errno;
  545.     (void) fprintf(stderr, "exiting fork with %ld", (long) ret);
  546.     if (ret == (pid_t) -1)
  547.         (void) fprintf(stderr, "; errno: %d", err);
  548.     (void) fprintf(stderr, "\n");
  549.     (void) fflush(stderr);
  550.     return ret;
  551. }
  552.  
  553. int posix_debug_execl (const char *path, const char *arg, ...)
  554. {
  555.     va_list va;
  556.     int ret, err, i;
  557.     const char *args[NARGS];
  558.  
  559.     va_start(va, arg);
  560.     (void) fprintf(stderr, "entering execl(%s, %s", canonical_string(path), canonical_string(arg));
  561.     for (i = 0; i < NARGS; ++i)
  562.     {
  563.         args[i] = va_arg(va, const char *);
  564.         (void) fprintf(stderr, ", %s", canonical_string(args[i]));
  565.         if (args[i] == NULL)
  566.             break;
  567.     }
  568.     va_end(va);
  569.     if (i == NARGS)
  570.         (void) fprintf(stderr, ", ..., NULL");
  571.     (void) fprintf(stderr, ")\n");
  572.     (void) fflush(stderr);
  573.     if (i == 0)
  574.         ret = execl(path, arg, NULL);
  575.     else if (i == 1)
  576.         ret = execl(path, arg, args[0], NULL);
  577.     else if (i == 2)
  578.         ret = execl(path, arg, args[0], args[1], NULL);
  579.     else if (i == 3)
  580.         ret = execl(path, arg, args[0], args[1], args[2], NULL);
  581.     else if (i == 4)
  582.         ret = execl(path, arg, args[0], args[1], args[2], args[3], NULL);
  583.     else if (i == 5)
  584.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], NULL);
  585.     else if (i == 6)
  586.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], NULL);
  587.     else if (i == 7)
  588.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], NULL);
  589.     else if (i == 8)
  590.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], NULL);
  591.     else if (i == 9)
  592.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], NULL);
  593.     else if (i == 10)
  594.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  595.             NULL);
  596.     else if (i == 11)
  597.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  598.             args[10], NULL);
  599.     else if (i == 12)
  600.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  601.             args[10], args[11], NULL);
  602.     else if (i == 13)
  603.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  604.             args[10], args[11], args[12], NULL);
  605.     else if (i == 14)
  606.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  607.             args[10], args[11], args[12], args[13], NULL);
  608.     else if (i == 15)
  609.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  610.             args[10], args[11], args[12], args[13], args[14], NULL);
  611.     else
  612.         ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  613.             args[10], args[11], args[12], args[13], args[14], args[15], NULL);
  614. /*
  615.     If NARGS changes from its original value of 16, add or subtract "if" cases according to this pattern.
  616. */
  617.     err = errno;
  618.     (void) fprintf(stderr, "exiting execl with %d", ret);
  619.     if (ret == -1)
  620.         (void) fprintf(stderr, "; errno: %d", err);
  621.     (void) fprintf(stderr, "\n");
  622.     (void) fflush(stderr);
  623.     return ret;
  624. }
  625.  
  626. int posix_debug_execv (const char *path, char * const argv[])
  627. {
  628.     int ret, err;
  629.  
  630.     (void) fprintf(stderr, "entering execv(%s, %p)\n", canonical_string(path), argv);
  631.     (void) fflush(stderr);
  632.     ret = execv(path, argv);
  633.     err = errno;
  634.     (void) fprintf(stderr, "exiting execv with %d", ret);
  635.     if (ret == -1)
  636.         (void) fprintf(stderr, "; errno: %d", err);
  637.     (void) fprintf(stderr, "\n");
  638.     (void) fflush(stderr);
  639.     return ret;
  640. }
  641.  
  642. int posix_debug_execle (const char *path, const char *arg, ...)
  643. {
  644.     va_list va;
  645.     int ret, err, i, j;
  646.     const char *args[NARGS];
  647.     const char *envp[NENVS]; /* POSIX says it should be char * const [], but that's unassignable! */
  648.  
  649.     (void) fprintf(stderr, "entering execle(%s, %s", canonical_string(path), canonical_string(arg));
  650.     for (i = 0; i < NARGS; ++i)
  651.     {
  652.         args[i] = va_arg(va, const char *);
  653.         (void) fprintf(stderr, ", %s", canonical_string(args[i]));
  654.         if (args[i] == NULL)
  655.             break;
  656.     }
  657.     if (i == NARGS)
  658.     {
  659.         while (va_arg(va, const char *) != NULL)
  660.             ;
  661.         (void) fprintf(stderr, ", ..., NULL");
  662.     }
  663.     for (j = 0; j < NENVS; ++j)
  664.     {
  665.         envp[j] = va_arg(va, char * const);
  666.         (void) fprintf(stderr, ", %s", canonical_string(envp[j]));
  667.         if (envp[j] == NULL)
  668.             break;
  669.     }
  670.     if (j == NENVS)
  671.     {
  672.         envp[NENVS - 1] = NULL;
  673.         (void) fprintf(stderr, ", ..., NULL");
  674.     }
  675.     va_end(va);
  676.     (void) fprintf(stderr, ")\n");
  677.     (void) fflush(stderr);
  678.     if (i == 0)
  679.         ret = execle(path, arg, NULL, envp);
  680.     else if (i == 1)
  681.         ret = execle(path, arg, args[0], NULL, envp);
  682.     else if (i == 2)
  683.         ret = execle(path, arg, args[0], args[1], NULL, envp);
  684.     else if (i == 3)
  685.         ret = execle(path, arg, args[0], args[1], args[2], NULL, envp);
  686.     else if (i == 4)
  687.         ret = execle(path, arg, args[0], args[1], args[2], args[3], NULL, envp);
  688.     else if (i == 5)
  689.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], NULL, envp);
  690.     else if (i == 6)
  691.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], NULL, envp);
  692.     else if (i == 7)
  693.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], NULL, envp);
  694.     else if (i == 8)
  695.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], NULL, envp);
  696.     else if (i == 9)
  697.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], NULL,
  698.             envp);
  699.     else if (i == 10)
  700.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  701.             NULL, envp);
  702.     else if (i == 11)
  703.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  704.             args[10], NULL, envp);
  705.     else if (i == 12)
  706.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  707.             args[10], args[11], NULL, envp);
  708.     else if (i == 13)
  709.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  710.             args[10], args[11], args[12], NULL, envp);
  711.     else if (i == 14)
  712.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  713.             args[10], args[11], args[12], args[13], NULL, envp);
  714.     else if (i == 15)
  715.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  716.             args[10], args[11], args[12], args[13], args[14], NULL, envp);
  717.     else
  718.         ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  719.             args[10], args[11], args[12], args[13], args[14], args[15], NULL, envp);
  720. /*
  721.     If NARGS changes from its original value of 16, add or subtract "if" cases according to this pattern.
  722. */
  723.     err = errno;
  724.     (void) fprintf(stderr, "exiting execle with %d", ret);
  725.     if (ret == -1)
  726.         (void) fprintf(stderr, "; errno: %d", err);
  727.     (void) fprintf(stderr, "\n");
  728.     (void) fflush(stderr);
  729.     return ret;
  730. }
  731.  
  732. int posix_debug_execve (const char *path, char * const argv[], char * const envp[])
  733. {
  734.     int ret, err;
  735.  
  736.     (void) fprintf(stderr, "entering execve(%s, %p, %p)\n", canonical_string(path), argv, envp);
  737.     (void) fflush(stderr);
  738.     ret = execve(path, argv, envp);
  739.     err = errno;
  740.     (void) fprintf(stderr, "exiting execve with %d", ret);
  741.     if (ret == -1)
  742.         (void) fprintf(stderr, "; errno: %d", err);
  743.     (void) fprintf(stderr, "\n");
  744.     (void) fflush(stderr);
  745.     return ret;
  746. }
  747.  
  748. int posix_debug_execlp (const char *file, const char *arg, ...)
  749. {
  750.     va_list va;
  751.     int ret, err, i;
  752.     const char *args[NARGS];
  753.  
  754.     va_start(va, arg);
  755.     (void) fprintf(stderr, "entering execlp(%s, %s", canonical_string(file), canonical_string(arg));
  756.     for (i = 0; i < NARGS; ++i)
  757.     {
  758.         args[i] = va_arg(va, const char *);
  759.         (void) fprintf(stderr, ", %s", canonical_string(args[i]));
  760.         if (args[i] == NULL)
  761.             break;
  762.     }
  763.     va_end(va);
  764.     if (i == NARGS)
  765.         (void) fprintf(stderr, ", ..., NULL");
  766.     (void) fprintf(stderr, ")\n");
  767.     (void) fflush(stderr);
  768.     if (i == 0)
  769.         ret = execlp(file, arg, NULL);
  770.     else if (i == 1)
  771.         ret = execlp(file, arg, args[0], NULL);
  772.     else if (i == 2)
  773.         ret = execlp(file, arg, args[0], args[1], NULL);
  774.     else if (i == 3)
  775.         ret = execlp(file, arg, args[0], args[1], args[2], NULL);
  776.     else if (i == 4)
  777.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], NULL);
  778.     else if (i == 5)
  779.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], NULL);
  780.     else if (i == 6)
  781.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], NULL);
  782.     else if (i == 7)
  783.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], NULL);
  784.     else if (i == 8)
  785.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], NULL);
  786.     else if (i == 9)
  787.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], NULL);
  788.     else if (i == 10)
  789.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  790.             NULL);
  791.     else if (i == 11)
  792.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  793.             args[10], NULL);
  794.     else if (i == 12)
  795.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  796.             args[10], args[11], NULL);
  797.     else if (i == 13)
  798.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  799.             args[10], args[11], args[12], NULL);
  800.     else if (i == 14)
  801.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  802.             args[10], args[11], args[12], args[13], NULL);
  803.     else if (i == 15)
  804.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  805.             args[10], args[11], args[12], args[13], args[14], NULL);
  806.     else
  807.         ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  808.             args[10], args[11], args[12], args[13], args[14], args[15], NULL);
  809. /*
  810.     If NARGS changes from its original value of 16, add or subtract "if" cases according to this pattern.
  811. */
  812.     err = errno;
  813.     (void) fprintf(stderr, "exiting execlp with %d", ret);
  814.     if (ret == -1)
  815.         (void) fprintf(stderr, "; errno: %d", err);
  816.     (void) fprintf(stderr, "\n");
  817.     (void) fflush(stderr);
  818.     return ret;
  819. }
  820.  
  821. int posix_debug_execvp (const char *file, char * const argv[])
  822. {
  823.     int ret, err;
  824.  
  825.     (void) fprintf(stderr, "entering execvp(%s, %p)\n", canonical_string(file), argv);
  826.     (void) fflush(stderr);
  827.     ret = execvp(file, argv);
  828.     err = errno;
  829.     (void) fprintf(stderr, "exiting execvp with %d", ret);
  830.     if (ret == -1)
  831.         (void) fprintf(stderr, "; errno: %d", err);
  832.     (void) fprintf(stderr, "\n");
  833.     (void) fflush(stderr);
  834.     return ret;
  835. }
  836.  
  837. pid_t posix_debug_wait (int *statloc)
  838. {
  839.     pid_t ret;
  840.     int err;
  841.  
  842.     (void) fprintf(stderr, "entering wait(%p)\n", statloc);
  843.     (void) fflush(stderr);
  844.     ret = wait(statloc);
  845.     err = errno;
  846.     (void) fprintf(stderr, "exiting wait with %ld", (long) ret);
  847.     if (ret == (pid_t) -1)
  848.         (void) fprintf(stderr, "; errno: %d", err);
  849.     (void) fprintf(stderr, "\n");
  850.     (void) fflush(stderr);
  851.     return ret;
  852. }
  853.  
  854. pid_t posix_debug_waitpid (pid_t pid, int *statloc, int options)
  855. {
  856.     pid_t ret;
  857.     int err;
  858.  
  859.     (void) fprintf(stderr, "entering waitpid(%ld, %p, %s)\n", (long) pid, statloc, options_string(options));
  860.     (void) fflush(stderr);
  861.     ret = waitpid(pid, statloc, options);
  862.     err = errno;
  863.     (void) fprintf(stderr, "exiting waitpid with %ld", (long) ret);
  864.     if (ret == (pid_t) -1)
  865.         (void) fprintf(stderr, "; errno: %d", err);
  866.     (void) fprintf(stderr, "\n");
  867.     (void) fflush(stderr);
  868.     return ret;
  869. }
  870.  
  871. void posix_debug__exit (int status)
  872. {
  873.     int err, saved_errno;
  874.  
  875.     (void) fprintf(stderr, "entering _exit(%d)\n", status);
  876.     (void) fflush(stderr);
  877.     saved_errno = errno;
  878.     _exit(status);
  879.     err = errno;
  880.     (void) fprintf(stderr, "exiting _exit");
  881.     if (saved_errno != err)
  882.         (void) fprintf(stderr, "; errno: %d", err);
  883.     (void) fprintf(stderr, "\n");
  884.     (void) fflush(stderr);
  885. }
  886.  
  887. int posix_debug_kill (pid_t pid, int sig)
  888. {
  889.     int ret, err;
  890.  
  891.     (void) fprintf(stderr, "entering kill(%ld, %s)\n", (long) pid, signum_string(sig));
  892.     (void) fflush(stderr);
  893.     ret = kill(pid, sig);
  894.     err = errno;
  895.     (void) fprintf(stderr, "exiting kill with %d", ret);
  896.     if (ret == -1)
  897.         (void) fprintf(stderr, "; errno: %d", err);
  898.     (void) fprintf(stderr, "\n");
  899.     (void) fflush(stderr);
  900.     return ret;
  901. }
  902.  
  903. int posix_debug_sigemptyset (sigset_t *set)
  904. {
  905.     int ret, err;
  906.  
  907.     (void) fprintf(stderr, "entering sigemptyset(%p)\n", set);
  908.     (void) fflush(stderr);
  909.     ret = sigemptyset(set);
  910.     err = errno;
  911.     (void) fprintf(stderr, "exiting sigemptyset with %d", ret);
  912.     if (ret == -1)
  913.         (void) fprintf(stderr, "; errno: %d", err);
  914.     (void) fprintf(stderr, "\n");
  915.     (void) fflush(stderr);
  916.     return ret;
  917. }
  918.  
  919. int posix_debug_sigfillset (sigset_t *set)
  920. {
  921.     int ret, err;
  922.  
  923.     (void) fprintf(stderr, "entering sigfillset(%p)\n", set);
  924.     (void) fflush(stderr);
  925.     ret = sigfillset(set);
  926.     err = errno;
  927.     (void) fprintf(stderr, "exiting sigfillset with %d", ret);
  928.     if (ret == -1)
  929.         (void) fprintf(stderr, "; errno: %d", err);
  930.     (void) fprintf(stderr, "\n");
  931.     (void) fflush(stderr);
  932.     return ret;
  933. }
  934.  
  935. int posix_debug_sigaddset (sigset_t *set, int signo)
  936. {
  937.     int ret, err;
  938.  
  939.     (void) fprintf(stderr, "entering sigaddset(%p, %s)\n", set, signum_string(signo));
  940.     (void) fflush(stderr);
  941.     ret = sigaddset(set, signo);
  942.     err = errno;
  943.     (void) fprintf(stderr, "exiting sigaddset with %d", ret);
  944.     if (ret == -1)
  945.         (void) fprintf(stderr, "; errno: %d", err);
  946.     (void) fprintf(stderr, "\n");
  947.     (void) fflush(stderr);
  948.     return ret;
  949. }
  950.  
  951. int posix_debug_sigdelset (sigset_t *set, int signo)
  952. {
  953.     int ret, err;
  954.  
  955.     (void) fprintf(stderr, "entering sigdelset(%p, %s)\n", set, signum_string(signo));
  956.     (void) fflush(stderr);
  957.     ret = sigdelset(set, signo);
  958.     err = errno;
  959.     (void) fprintf(stderr, "exiting sigdelset with %d", ret);
  960.     if (ret == -1)
  961.         (void) fprintf(stderr, "; errno: %d", err);
  962.     (void) fprintf(stderr, "\n");
  963.     (void) fflush(stderr);
  964.     return ret;
  965. }
  966.  
  967. int posix_debug_sigismember (const sigset_t *set, int signo)
  968. {
  969.     int ret, err;
  970.  
  971.     (void) fprintf(stderr, "entering sigismember(%p, %s)\n", set, signum_string(signo));
  972.     (void) fflush(stderr);
  973.     ret = sigismember(set, signo);
  974.     err = errno;
  975.     (void) fprintf(stderr, "exiting sigismember with %d", ret);
  976.     if (ret == -1)
  977.         (void) fprintf(stderr, "; errno: %d", err);
  978.     (void) fprintf(stderr, "\n");
  979.     (void) fflush(stderr);
  980.     return ret;
  981. }
  982.  
  983. int posix_debug_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  984. {
  985.     int ret, err;
  986.  
  987.     (void) fprintf(stderr, "entering sigaction(%s, %p, %p)\n", signum_string(sig), act, oact);
  988.     (void) fflush(stderr);
  989.     ret = sigaction(sig, act, oact);
  990.     err = errno;
  991.     (void) fprintf(stderr, "exiting sigaction with %d", ret);
  992.     if (ret == -1)
  993.         (void) fprintf(stderr, "; errno: %d", err);
  994.     (void) fprintf(stderr, "\n");
  995.     (void) fflush(stderr);
  996.     return ret;
  997. }
  998.  
  999. int posix_debug_sigprocmask (int how, const sigset_t *set, sigset_t *oset)
  1000. {
  1001.     int ret, err;
  1002.  
  1003.     (void) fprintf(stderr, "entering sigprocmask(%s, %p, %p)\n", how_string(how), set, oset);
  1004.     (void) fflush(stderr);
  1005.     ret = sigprocmask(how, set, oset);
  1006.     err = errno;
  1007.     (void) fprintf(stderr, "exiting sigprocmask with %d", ret);
  1008.     if (ret == -1)
  1009.         (void) fprintf(stderr, "; errno: %d", err);
  1010.     (void) fprintf(stderr, "\n");
  1011.     (void) fflush(stderr);
  1012.     return ret;
  1013. }
  1014.  
  1015. int posix_debug_sigpending (sigset_t *set)
  1016. {
  1017.     int ret, err;
  1018.  
  1019.     (void) fprintf(stderr, "entering sigpending(%p)\n", set);
  1020.     (void) fflush(stderr);
  1021.     ret = sigpending(set);
  1022.     err = errno;
  1023.     (void) fprintf(stderr, "exiting sigpending with %d", ret);
  1024.     if (ret == -1)
  1025.         (void) fprintf(stderr, "; errno: %d", err);
  1026.     (void) fprintf(stderr, "\n");
  1027.     (void) fflush(stderr);
  1028.     return ret;
  1029. }
  1030.  
  1031. int posix_debug_sigsuspend (const sigset_t *sigmask)
  1032. {
  1033.     int ret, err;
  1034.  
  1035.     (void) fprintf(stderr, "entering sigsuspend(%p)\n", sigmask);
  1036.     (void) fflush(stderr);
  1037.     ret = sigsuspend(sigmask);
  1038.     err = errno;
  1039.     (void) fprintf(stderr, "exiting sigsuspend with %d", ret);
  1040.     if (ret == -1)
  1041.         (void) fprintf(stderr, "; errno: %d", err);
  1042.     (void) fprintf(stderr, "\n");
  1043.     (void) fflush(stderr);
  1044.     return ret;
  1045. }
  1046.  
  1047. unsigned int posix_debug_alarm (unsigned int seconds)
  1048. {
  1049.     unsigned int ret;
  1050.  
  1051.     (void) fprintf(stderr, "entering alarm(%u)\n", seconds);
  1052.     (void) fflush(stderr);
  1053.     ret = alarm(seconds);
  1054.     (void) fprintf(stderr, "exiting alarm with %u\n", ret);
  1055.     (void) fflush(stderr);
  1056.     return ret;
  1057. }
  1058.  
  1059. int posix_debug_pause (void)
  1060. {
  1061.     int ret, err;
  1062.  
  1063.     (void) fprintf(stderr, "entering pause()\n");
  1064.     (void) fflush(stderr);
  1065.     ret = pause();
  1066.     err = errno;
  1067.     (void) fprintf(stderr, "exiting pause with %d", ret);
  1068.     if (ret == -1)
  1069.         (void) fprintf(stderr, "; errno: %d", err);
  1070.     (void) fprintf(stderr, "\n");
  1071.     (void) fflush(stderr);
  1072.     return ret;
  1073. }
  1074.  
  1075. unsigned int posix_debug_sleep (unsigned int seconds)
  1076. {
  1077.     unsigned int ret;
  1078.  
  1079.     (void) fprintf(stderr, "entering sleep(%u)\n", seconds);
  1080.     (void) fflush(stderr);
  1081.     ret = sleep(seconds);
  1082.     (void) fprintf(stderr, "exiting sleep with %u\n", ret);
  1083.     (void) fflush(stderr);
  1084.     return ret;
  1085. }
  1086.  
  1087. /* Section 4: Process Environment */
  1088.  
  1089. pid_t posix_debug_getpid (void)
  1090. {
  1091.     pid_t ret;
  1092.  
  1093.     (void) fprintf(stderr, "entering getpid()\n");
  1094.     (void) fflush(stderr);
  1095.     ret = getpid();
  1096.     (void) fprintf(stderr, "exiting getpid with %ld\n", (long) ret);
  1097.     (void) fflush(stderr);
  1098.     return ret;
  1099. }
  1100.  
  1101. pid_t posix_debug_getppid (void)
  1102. {
  1103.     pid_t ret;
  1104.  
  1105.     (void) fprintf(stderr, "entering getppid()\n");
  1106.     (void) fflush(stderr);
  1107.     ret = getppid();
  1108.     (void) fprintf(stderr, "exiting getppid with %ld\n", (long) ret);
  1109.     (void) fflush(stderr);
  1110.     return ret;
  1111. }
  1112.  
  1113. uid_t posix_debug_getuid (void)
  1114. {
  1115.     uid_t ret;
  1116.  
  1117.     (void) fprintf(stderr, "entering getuid()\n");
  1118.     (void) fflush(stderr);
  1119.     ret = getuid();
  1120.     (void) fprintf(stderr, "exiting getuid with %lu\n", (unsigned long) ret);
  1121.     (void) fflush(stderr);
  1122.     return ret;
  1123. }
  1124.  
  1125. uid_t posix_debug_geteuid (void)
  1126. {
  1127.     uid_t ret;
  1128.  
  1129.     (void) fprintf(stderr, "entering geteuid()\n");
  1130.     (void) fflush(stderr);
  1131.     ret = geteuid();
  1132.     (void) fprintf(stderr, "exiting geteuid with %lu\n", (unsigned long) ret);
  1133.     (void) fflush(stderr);
  1134.     return ret;
  1135. }
  1136.  
  1137. gid_t posix_debug_getgid (void)
  1138. {
  1139.     gid_t ret;
  1140.  
  1141.     (void) fprintf(stderr, "entering getgid()\n");
  1142.     (void) fflush(stderr);
  1143.     ret = getgid();
  1144.     (void) fprintf(stderr, "exiting getgid with %lu\n", (unsigned long) ret);
  1145.     (void) fflush(stderr);
  1146.     return ret;
  1147. }
  1148.  
  1149. gid_t posix_debug_getegid (void)
  1150. {
  1151.     gid_t ret;
  1152.  
  1153.     (void) fprintf(stderr, "entering getegid()\n");
  1154.     (void) fflush(stderr);
  1155.     ret = getegid();
  1156.     (void) fprintf(stderr, "exiting getegid with %lu\n", (unsigned long) ret);
  1157.     (void) fflush(stderr);
  1158.     return ret;
  1159. }
  1160.  
  1161. int posix_debug_setuid (uid_t uid)
  1162. {
  1163.     int ret, err;
  1164.  
  1165.     (void) fprintf(stderr, "entering setuid(%lu)\n", (unsigned long) uid);
  1166.     (void) fflush(stderr);
  1167.     ret = setuid(uid);
  1168.     err = errno;
  1169.     (void) fprintf(stderr, "exiting setuid with %d", ret);
  1170.     if (ret == -1)
  1171.         (void) fprintf(stderr, "; errno: %d", err);
  1172.     (void) fprintf(stderr, "\n");
  1173.     (void) fflush(stderr);
  1174.     return ret;
  1175. }
  1176.  
  1177. int posix_debug_setgid (gid_t gid)
  1178. {
  1179.     int ret, err;
  1180.  
  1181.     (void) fprintf(stderr, "entering setgid(%lu)\n", (unsigned long) gid);
  1182.     (void) fflush(stderr);
  1183.     ret = setgid(gid);
  1184.     err = errno;
  1185.     (void) fprintf(stderr, "exiting setgid with %d", ret);
  1186.     if (ret == -1)
  1187.         (void) fprintf(stderr, "; errno: %d", err);
  1188.     (void) fprintf(stderr, "\n");
  1189.     (void) fflush(stderr);
  1190.     return ret;
  1191. }
  1192.  
  1193. int posix_debug_getgroups (int gidsetsize, gid_t grouplist[])
  1194. {
  1195.     int ret, err;
  1196.  
  1197.     (void) fprintf(stderr, "entering getgroups(%d, %p)\n", gidsetsize, grouplist);
  1198.     (void) fflush(stderr);
  1199.     ret = getgroups(gidsetsize, grouplist);
  1200.     err = errno;
  1201.     (void) fprintf(stderr, "exiting getgroups with %d", ret);
  1202.     if (ret == -1)
  1203.         (void) fprintf(stderr, "; errno: %d", err);
  1204.     (void) fprintf(stderr, "\n");
  1205.     (void) fflush(stderr);
  1206.     return ret;
  1207. }
  1208.  
  1209. char *posix_debug_getlogin (void)
  1210. {
  1211.     char *ret;
  1212.  
  1213.     (void) fprintf(stderr, "entering getlogin()\n");
  1214.     (void) fflush(stderr);
  1215.     ret = getlogin();
  1216.     (void) fprintf(stderr, "exiting getlogin with %s\n", canonical_string(ret));
  1217.     (void) fflush(stderr);
  1218.     return ret;
  1219. }
  1220.  
  1221. pid_t posix_debug_getpgrp (void)
  1222. {
  1223.     pid_t ret;
  1224.  
  1225.     (void) fprintf(stderr, "entering getpgrp()\n");
  1226.     (void) fflush(stderr);
  1227.     ret = getpgrp();
  1228.     (void) fprintf(stderr, "exiting getpgrp with %ld\n", (long) ret);
  1229.     (void) fflush(stderr);
  1230.     return ret;
  1231. }
  1232.  
  1233. pid_t posix_debug_setsid (void)
  1234. {
  1235.     pid_t ret;
  1236.     int err;
  1237.  
  1238.     (void) fprintf(stderr, "entering setsid()\n");
  1239.     (void) fflush(stderr);
  1240.     ret = setsid();
  1241.     err = errno;
  1242.     (void) fprintf(stderr, "exiting setsid with %ld", (long) ret);
  1243.     if (ret == (pid_t) -1)
  1244.         (void) fprintf(stderr, "; errno: %d", err);
  1245.     (void) fprintf(stderr, "\n");
  1246.     (void) fflush(stderr);
  1247.     return ret;
  1248. }
  1249.  
  1250. int posix_debug_setpgid (pid_t pid, pid_t pgid)
  1251. {
  1252.     int ret, err;
  1253.  
  1254.     (void) fprintf(stderr, "entering setpgid(%ld, %ld)\n", (long) pid, (long) pgid);
  1255.     (void) fflush(stderr);
  1256.     ret = setpgid(pid, pgid);
  1257.     err = errno;
  1258.     (void) fprintf(stderr, "exiting setpgid with %d", ret);
  1259.     if (ret == -1)
  1260.         (void) fprintf(stderr, "; errno: %d", err);
  1261.     (void) fprintf(stderr, "\n");
  1262.     (void) fflush(stderr);
  1263.     return ret;
  1264. }
  1265.  
  1266. int posix_debug_uname (struct utsname *name)
  1267. {
  1268.     int ret, err;
  1269.  
  1270.     (void) fprintf(stderr, "entering uname(%p)\n", name);
  1271.     (void) fflush(stderr);
  1272.     ret = uname(name);
  1273.     err = errno;
  1274.     (void) fprintf(stderr, "exiting uname with %d", ret);
  1275.     if (ret == -1)
  1276.         (void) fprintf(stderr, "; errno: %d", err);
  1277.     (void) fprintf(stderr, "\n");
  1278.     (void) fflush(stderr);
  1279.     return ret;
  1280. }
  1281.  
  1282. time_t posix_debug_time (time_t *tloc)
  1283. {
  1284.     time_t ret;
  1285.     int err;
  1286.  
  1287.     (void) fprintf(stderr, "entering time(%p)\n", tloc);
  1288.     (void) fflush(stderr);
  1289.     ret = time(tloc);
  1290.     err = errno;
  1291.     (void) fprintf(stderr, "exiting time with %ld", (long) ret);
  1292.     if (ret == (time_t) -1)
  1293.         (void) fprintf(stderr, "; errno: %d", err);
  1294.     (void) fprintf(stderr, "\n");
  1295.     (void) fflush(stderr);
  1296.     return ret;
  1297. }
  1298.  
  1299. clock_t posix_debug_times (struct tms *buffer)
  1300. {
  1301.     clock_t ret;
  1302.     int err;
  1303.  
  1304.     (void) fprintf(stderr, "entering times(%p)\n", buffer);
  1305.     (void) fflush(stderr);
  1306.     ret = times(buffer);
  1307.     err = errno;
  1308.     (void) fprintf(stderr, "exiting times with %ld", (long) ret);
  1309.     if (ret == (clock_t) -1)
  1310.         (void) fprintf(stderr, "; errno: %d", err);
  1311.     (void) fprintf(stderr, "\n");
  1312.     (void) fflush(stderr);
  1313.     return ret;
  1314. }
  1315.  
  1316. char *posix_debug_getenv (const char *name)
  1317. {
  1318.     char *ret;
  1319.  
  1320.     (void) fprintf(stderr, "entering getenv(%s)\n", canonical_string(name));
  1321.     (void) fflush(stderr);
  1322.     ret = getenv(name);
  1323.     (void) fprintf(stderr, "exiting getenv with %s\n", canonical_string(ret));
  1324.     (void) fflush(stderr);
  1325.     return ret;
  1326. }
  1327.  
  1328. char *posix_debug_ctermid (char *s)
  1329. {
  1330.     char *ret;
  1331.  
  1332.     (void) fprintf(stderr, "entering ctermid(%s)\n", canonical_string(s));
  1333.     (void) fflush(stderr);
  1334.     ret = ctermid(s);
  1335.     (void) fprintf(stderr, "exiting ctermid with %s\n", canonical_string(ret));
  1336.     (void) fflush(stderr);
  1337.     return ret;
  1338. }
  1339.  
  1340. char *posix_debug_ttyname (int fildes)
  1341. {
  1342.     char *ret;
  1343.  
  1344.     (void) fprintf(stderr, "entering ttyname(%d)\n", fildes);
  1345.     (void) fflush(stderr);
  1346.     ret = ttyname(fildes);
  1347.     (void) fprintf(stderr, "exiting ttyname with %s\n", canonical_string(ret));
  1348.     (void) fflush(stderr);
  1349.     return ret;
  1350. }
  1351.  
  1352. int posix_debug_isatty (int fildes)
  1353. {
  1354.     int ret;
  1355.  
  1356.     (void) fprintf(stderr, "entering isatty(%d)\n", fildes);
  1357.     (void) fflush(stderr);
  1358.     ret = isatty(fildes);
  1359.     (void) fprintf(stderr, "exiting isatty with %d\n", ret);
  1360.     (void) fflush(stderr);
  1361.     return ret;
  1362. }
  1363.  
  1364. long posix_debug_sysconf (int name)
  1365. {
  1366.     long ret;
  1367.     int err, saved_errno;
  1368.  
  1369.     (void) fprintf(stderr, "entering sysconf(%s)\n", scname_string(name));
  1370.     (void) fflush(stderr);
  1371.     saved_errno = errno;
  1372.     ret = sysconf(name);
  1373.     err = errno;
  1374.     (void) fprintf(stderr, "exiting sysconf with %ld", (long) ret);
  1375.     if (ret == (long) -1 && saved_errno != err)
  1376.         (void) fprintf(stderr, "; errno: %d", err);
  1377.     (void) fprintf(stderr, "\n");
  1378.     (void) fflush(stderr);
  1379.     return ret;
  1380. }
  1381.  
  1382. /* Section 5: Files and Directories */
  1383.  
  1384. DIR *posix_debug_opendir (const char *dirname)
  1385. {
  1386.     DIR *ret;
  1387.     int err;
  1388.  
  1389.     (void) fprintf(stderr, "entering opendir(%s)\n", canonical_string(dirname));
  1390.     (void) fflush(stderr);
  1391.     ret = opendir(dirname);
  1392.     err = errno;
  1393.     (void) fprintf(stderr, "exiting opendir with %p", ret);
  1394.     if (ret == NULL)
  1395.         (void) fprintf(stderr, "; errno: %d", err);
  1396.     (void) fprintf(stderr, "\n");
  1397.     (void) fflush(stderr);
  1398.     return ret;
  1399. }
  1400.  
  1401. struct dirent *posix_debug_readdir (DIR *dirp)
  1402. {
  1403.     struct dirent *ret;
  1404.     int err;
  1405.  
  1406.     (void) fprintf(stderr, "entering readdir(%p)\n", dirp);
  1407.     (void) fflush(stderr);
  1408.     ret = readdir(dirp);
  1409.     err = errno;
  1410.     (void) fprintf(stderr, "exiting readdir with %p", ret);
  1411.     if (ret == NULL)
  1412.         (void) fprintf(stderr, "; errno: %d", err);
  1413.     (void) fprintf(stderr, "\n");
  1414.     (void) fflush(stderr);
  1415.     return ret;
  1416. }
  1417.  
  1418. void posix_debug_rewinddir (DIR *dirp)
  1419. {
  1420.     int err, saved_errno;
  1421.  
  1422.     (void) fprintf(stderr, "entering rewinddir(%p)\n", dirp);
  1423.     (void) fflush(stderr);
  1424.     saved_errno = errno;
  1425.     rewinddir(dirp);
  1426.     err = errno;
  1427.     (void) fprintf(stderr, "exiting rewinddir");
  1428.     if (saved_errno != err)
  1429.         (void) fprintf(stderr, "; errno: %d\n", err);
  1430.     (void) fprintf(stderr, "\n");
  1431.     (void) fflush(stderr);
  1432. }
  1433.  
  1434. int posix_debug_closedir (DIR *dirp)
  1435. {
  1436.     int ret, err;
  1437.  
  1438.     (void) fprintf(stderr, "entering closedir(%p)\n", dirp);
  1439.     (void) fflush(stderr);
  1440.     ret = closedir(dirp);
  1441.     err = errno;
  1442.     (void) fprintf(stderr, "exiting closedir with %d", ret);
  1443.     if (ret == -1)
  1444.         (void) fprintf(stderr, "; errno: %d", err);
  1445.     (void) fprintf(stderr, "\n");
  1446.     (void) fflush(stderr);
  1447.     return ret;
  1448. }
  1449.  
  1450. int posix_debug_chdir (const char *path)
  1451. {
  1452.     int ret, err;
  1453.  
  1454.     (void) fprintf(stderr, "entering chdir(%s)\n", canonical_string(path));
  1455.     (void) fflush(stderr);
  1456.     ret = chdir(path);
  1457.     err = errno;
  1458.     (void) fprintf(stderr, "exiting chdir with %d", ret);
  1459.     if (ret == -1)
  1460.         (void) fprintf(stderr, "; errno: %d", err);
  1461.     (void) fprintf(stderr, "\n");
  1462.     (void) fflush(stderr);
  1463.     return ret;
  1464. }
  1465.  
  1466. char *posix_debug_getcwd (char *buf, size_t size)
  1467. {
  1468.     char *ret;
  1469.     int err;
  1470.  
  1471.     (void) fprintf(stderr, "entering getcwd(%p, %lu)\n", buf, (unsigned long) size);
  1472.     (void) fflush(stderr);
  1473.     ret = getcwd(buf, size);
  1474.     err = errno;
  1475.     (void) fprintf(stderr, "exiting getcwd with %s", canonical_string(ret));
  1476.     if (ret == NULL)
  1477.         (void) fprintf(stderr, "; errno: %d", err);
  1478.     (void) fprintf(stderr, "\n");
  1479.     (void) fflush(stderr);
  1480.     return ret;
  1481. }
  1482.  
  1483. int posix_debug_open (const char *path, int oflag, ...)
  1484. {
  1485.     va_list va;
  1486.     int ret, err;
  1487.     mode_t mode;
  1488.  
  1489.     va_start(va, oflag);
  1490.     (void) fprintf(stderr, "entering open(%s, %s", canonical_string(path), oflag_string(oflag));
  1491.     if (oflag & O_CREAT)
  1492.     {
  1493.         mode = va_arg(va, mode_t);
  1494.         (void) fprintf(stderr, ", %s", mode_string(mode));
  1495.     }
  1496.     va_end(va);
  1497.     (void) fprintf(stderr, ")\n");
  1498.     (void) fflush(stderr);
  1499.     if (oflag & O_CREAT)
  1500.         ret = open(path, oflag, mode);
  1501.     else
  1502.         ret = open(path, oflag);
  1503.     err = errno;
  1504.     (void) fprintf(stderr, "exiting open with %d", ret);
  1505.     if (ret == -1)
  1506.         (void) fprintf(stderr, "; errno: %d", err);
  1507.     (void) fprintf(stderr, "\n");
  1508.     (void) fflush(stderr);
  1509.     return ret;
  1510. }
  1511.  
  1512. int posix_debug_creat (const char *path, mode_t mode)
  1513. {
  1514.     int ret, err;
  1515.  
  1516.     (void) fprintf(stderr, "entering creat(%s, %s)\n", canonical_string(path), mode_string(mode));
  1517.     (void) fflush(stderr);
  1518.     ret = creat(path, mode);
  1519.     err = errno;
  1520.     (void) fprintf(stderr, "exiting creat with %d", ret);
  1521.     if (ret == -1)
  1522.         (void) fprintf(stderr, "; errno: %d", err);
  1523.     (void) fprintf(stderr, "\n");
  1524.     (void) fflush(stderr);
  1525.     return ret;
  1526. }
  1527.  
  1528. mode_t posix_debug_umask (mode_t cmask)
  1529. {
  1530.     mode_t ret;
  1531.  
  1532.     (void) fprintf(stderr, "entering umask(%s)\n", mode_string(cmask));
  1533.     (void) fflush(stderr);
  1534.     ret = umask(cmask);
  1535.     (void) fprintf(stderr, "exiting umask with %s\n", mode_string(ret));
  1536.     (void) fflush(stderr);
  1537.     return ret;
  1538. }
  1539.  
  1540. int posix_debug_link (const char *existing, const char *new)
  1541. {
  1542.     int ret, err;
  1543.  
  1544.     (void) fprintf(stderr, "entering link(%s, %s)\n", canonical_string(existing), canonical_string(new));
  1545.     (void) fflush(stderr);
  1546.     ret = link(existing, new);
  1547.     err = errno;
  1548.     (void) fprintf(stderr, "exiting link with %d", ret);
  1549.     if (ret == -1)
  1550.         (void) fprintf(stderr, "; errno: %d", err);
  1551.     (void) fprintf(stderr, "\n");
  1552.     (void) fflush(stderr);
  1553.     return ret;
  1554. }
  1555.  
  1556. int posix_debug_mkdir (const char *path, mode_t mode)
  1557. {
  1558.     int ret, err;
  1559.  
  1560.     (void) fprintf(stderr, "entering mkdir(%s, %s)\n", canonical_string(path), mode_string(mode));
  1561.     (void) fflush(stderr);
  1562.     ret = mkdir(path, mode);
  1563.     err = errno;
  1564.     (void) fprintf(stderr, "exiting mkdir with %d", ret);
  1565.     if (ret == -1)
  1566.         (void) fprintf(stderr, "; errno: %d", err);
  1567.     (void) fprintf(stderr, "\n");
  1568.     (void) fflush(stderr);
  1569.     return ret;
  1570. }
  1571.  
  1572. int posix_debug_mkfifo (const char *path, mode_t mode)
  1573. {
  1574.     int ret, err;
  1575.  
  1576.     (void) fprintf(stderr, "entering mkfifo(%s, %s)\n", canonical_string(path), mode_string(mode));
  1577.     (void) fflush(stderr);
  1578.     ret = mkfifo(path, mode);
  1579.     err = errno;
  1580.     (void) fprintf(stderr, "exiting mkfifo with %d", ret);
  1581.     if (ret == -1)
  1582.         (void) fprintf(stderr, "; errno: %d", err);
  1583.     (void) fprintf(stderr, "\n");
  1584.     (void) fflush(stderr);
  1585.     return ret;
  1586. }
  1587.  
  1588. int posix_debug_unlink (const char *path)
  1589. {
  1590.     int ret, err;
  1591.  
  1592.     (void) fprintf(stderr, "entering unlink(%s)\n", canonical_string(path));
  1593.     (void) fflush(stderr);
  1594.     ret = unlink(path);
  1595.     err = errno;
  1596.     (void) fprintf(stderr, "exiting unlink with %d", ret);
  1597.     if (ret == -1)
  1598.         (void) fprintf(stderr, "; errno: %d", err);
  1599.     (void) fprintf(stderr, "\n");
  1600.     (void) fflush(stderr);
  1601.     return ret;
  1602. }
  1603.  
  1604. int posix_debug_rmdir (const char *path)
  1605. {
  1606.     int ret, err;
  1607.  
  1608.     (void) fprintf(stderr, "entering rmdir(%s)\n", canonical_string(path));
  1609.     (void) fflush(stderr);
  1610.     ret = rmdir(path);
  1611.     err = errno;
  1612.     (void) fprintf(stderr, "exiting rmdir with %d", ret);
  1613.     if (ret == -1)
  1614.         (void) fprintf(stderr, "; errno: %d", err);
  1615.     (void) fprintf(stderr, "\n");
  1616.     (void) fflush(stderr);
  1617.     return ret;
  1618. }
  1619.  
  1620. int posix_debug_rename (const char *old, const char *new)
  1621. {
  1622.     int ret, err;
  1623.  
  1624.     (void) fprintf(stderr, "entering rename(%s, %s)\n", canonical_string(old), canonical_string(new));
  1625.     (void) fflush(stderr);
  1626.     ret = rename(old, new);
  1627.     err = errno;
  1628.     (void) fprintf(stderr, "exiting rename with %d", ret);
  1629.     if (ret == -1)
  1630.         (void) fprintf(stderr, "; errno: %d", err);
  1631.     (void) fprintf(stderr, "\n");
  1632.     (void) fflush(stderr);
  1633.     return ret;
  1634. }
  1635.  
  1636. int posix_debug_stat (const char *path, struct stat *buf)
  1637. {
  1638.     int ret, err;
  1639.  
  1640.     (void) fprintf(stderr, "entering stat(%s, %p)\n", canonical_string(path), buf);
  1641.     (void) fflush(stderr);
  1642.     ret = stat(path, buf);
  1643.     err = errno;
  1644.     (void) fprintf(stderr, "exiting stat with %d", ret);
  1645.     if (ret == -1)
  1646.         (void) fprintf(stderr, "; errno: %d", err);
  1647.     (void) fprintf(stderr, "\n");
  1648.     (void) fflush(stderr);
  1649.     return ret;
  1650. }
  1651.  
  1652. int posix_debug_fstat (int fildes, struct stat *buf)
  1653. {
  1654.     int ret, err;
  1655.  
  1656.     (void) fprintf(stderr, "entering fstat(%d, %p)\n", fildes, buf);
  1657.     (void) fflush(stderr);
  1658.     ret = fstat(fildes, buf);
  1659.     err = errno;
  1660.     (void) fprintf(stderr, "exiting fstat with %d", ret);
  1661.     if (ret == -1)
  1662.         (void) fprintf(stderr, "; errno: %d", err);
  1663.     (void) fprintf(stderr, "\n");
  1664.     (void) fflush(stderr);
  1665.     return ret;
  1666. }
  1667.  
  1668. int posix_debug_access (const char *path, int amode)
  1669. {
  1670.     int ret, err;
  1671.  
  1672.     (void) fprintf(stderr, "entering access(%s, %s)\n", canonical_string(path), amode_string(amode));
  1673.     (void) fflush(stderr);
  1674.     ret = access(path, amode);
  1675.     err = errno;
  1676.     (void) fprintf(stderr, "exiting access with %d", ret);
  1677.     if (ret == -1)
  1678.         (void) fprintf(stderr, "; errno: %d", err);
  1679.     (void) fprintf(stderr, "\n");
  1680.     (void) fflush(stderr);
  1681.     return ret;
  1682. }
  1683.  
  1684. int posix_debug_chmod (const char *path, mode_t mode)
  1685. {
  1686.     int ret, err;
  1687.  
  1688.     (void) fprintf(stderr, "entering chmod(%s, %s)\n", canonical_string(path), mode_string(mode));
  1689.     (void) fflush(stderr);
  1690.     ret = chmod(path, mode);
  1691.     err = errno;
  1692.     (void) fprintf(stderr, "exiting chmod with %d", ret);
  1693.     if (ret == -1)
  1694.         (void) fprintf(stderr, "; errno: %d", err);
  1695.     (void) fprintf(stderr, "\n");
  1696.     (void) fflush(stderr);
  1697.     return ret;
  1698. }
  1699.  
  1700. int posix_debug_chown (const char *path, uid_t owner, gid_t group)
  1701. {
  1702.     int ret, err;
  1703.  
  1704.     (void) fprintf(stderr, "entering chown(%s, %lu, %lu)\n",
  1705.         canonical_string(path), (unsigned long) owner, (unsigned long) group);
  1706.     (void) fflush(stderr);
  1707.     ret = chown(path, owner, group);
  1708.     err = errno;
  1709.     (void) fprintf(stderr, "exiting chown with %d", ret);
  1710.     if (ret == -1)
  1711.         (void) fprintf(stderr, "; errno: %d", err);
  1712.     (void) fprintf(stderr, "\n");
  1713.     (void) fflush(stderr);
  1714.     return ret;
  1715. }
  1716.  
  1717. int posix_debug_utime (const char *path, const struct utimbuf *times)
  1718. {
  1719.     int ret, err;
  1720.  
  1721.     (void) fprintf(stderr, "entering utime(%s, %p)\n", canonical_string(path), times);
  1722.     (void) fflush(stderr);
  1723.     ret = utime(path, times);
  1724.     err = errno;
  1725.     (void) fprintf(stderr, "exiting utime with %d", ret);
  1726.     if (ret == -1)
  1727.         (void) fprintf(stderr, "; errno: %d", err);
  1728.     (void) fprintf(stderr, "\n");
  1729.     (void) fflush(stderr);
  1730.     return ret;
  1731. }
  1732.  
  1733. long posix_debug_pathconf (const char *path, int name)
  1734. {
  1735.     long ret;
  1736.     int err, saved_errno;
  1737.  
  1738.     (void) fprintf(stderr, "entering pathconf(%s, %s)\n", canonical_string(path), pcname_string(name));
  1739.     (void) fflush(stderr);
  1740.     saved_errno = errno;
  1741.     ret = pathconf(path, name);
  1742.     err = errno;
  1743.     (void) fprintf(stderr, "exiting pathconf with %ld", (long) ret);
  1744.     if (ret == (long) -1 && saved_errno != err)
  1745.         (void) fprintf(stderr, "; errno: %d", err);
  1746.     (void) fprintf(stderr, "\n");
  1747.     (void) fflush(stderr);
  1748.     return ret;
  1749. }
  1750.  
  1751. long posix_debug_fpathconf (int fildes, int name)
  1752. {
  1753.     long ret;
  1754.     int err, saved_errno;
  1755.  
  1756.     (void) fprintf(stderr, "entering fpathconf(%d, %s)\n", fildes, pcname_string(name));
  1757.     (void) fflush(stderr);
  1758.     saved_errno = errno;
  1759.     ret = fpathconf(fildes, name);
  1760.     err = errno;
  1761.     (void) fprintf(stderr, "exiting fpathconf with %ld", (long) ret);
  1762.     if (ret == (long) -1 && saved_errno != err)
  1763.         (void) fprintf(stderr, "; errno: %d", err);
  1764.     (void) fprintf(stderr, "\n");
  1765.     (void) fflush(stderr);
  1766.     return ret;
  1767. }
  1768.  
  1769. /* Section 6: Input and Output Primitives */
  1770.  
  1771. int posix_debug_pipe (int fildes[2])
  1772. {
  1773.     int ret, err;
  1774.  
  1775.     (void) fprintf(stderr, "entering pipe(%p)\n", fildes);
  1776.     (void) fflush(stderr);
  1777.     ret = pipe(fildes);
  1778.     err = errno;
  1779.     (void) fprintf(stderr, "exiting pipe with %d", ret);
  1780.     if (ret == -1)
  1781.         (void) fprintf(stderr, "; errno: %d", err);
  1782.     (void) fprintf(stderr, "\n");
  1783.     (void) fflush(stderr);
  1784.     return ret;
  1785. }
  1786.  
  1787. int posix_debug_dup (int fildes)
  1788. {
  1789.     int ret, err;
  1790.  
  1791.     (void) fprintf(stderr, "entering dup(%d)\n", fildes);
  1792.     (void) fflush(stderr);
  1793.     ret = dup(fildes);
  1794.     err = errno;
  1795.     (void) fprintf(stderr, "exiting dup with %d", ret);
  1796.     if (ret == -1)
  1797.         (void) fprintf(stderr, "; errno: %d", err);
  1798.     (void) fprintf(stderr, "\n");
  1799.     (void) fflush(stderr);
  1800.     return ret;
  1801. }
  1802.  
  1803. int posix_debug_dup2 (int fildes, int fildes2)
  1804. {
  1805.     int ret, err;
  1806.  
  1807.     (void) fprintf(stderr, "entering dup2(%d, %d)\n", fildes, fildes2);
  1808.     (void) fflush(stderr);
  1809.     ret = dup2(fildes, fildes2);
  1810.     err = errno;
  1811.     (void) fprintf(stderr, "exiting dup2 with %d", ret);
  1812.     if (ret == -1)
  1813.         (void) fprintf(stderr, "; errno: %d", err);
  1814.     (void) fprintf(stderr, "\n");
  1815.     (void) fflush(stderr);
  1816.     return ret;
  1817. }
  1818.  
  1819. int posix_debug_close (int fildes)
  1820. {
  1821.     int ret, err;
  1822.  
  1823.     (void) fprintf(stderr, "entering close(%d)\n", fildes);
  1824.     (void) fflush(stderr);
  1825.     ret = close(fildes);
  1826.     err = errno;
  1827.     (void) fprintf(stderr, "exiting close with %d", ret);
  1828.     if (ret == -1)
  1829.         (void) fprintf(stderr, "; errno: %d", err);
  1830.     (void) fprintf(stderr, "\n");
  1831.     (void) fflush(stderr);
  1832.     return ret;
  1833. }
  1834.  
  1835. ssize_t posix_debug_read (int fildes, void *buf, size_t nbyte)
  1836. {
  1837.     ssize_t ret;
  1838.     int err;
  1839.  
  1840.     (void) fprintf(stderr, "entering read(%d, %p, %lu)\n", fildes, buf, (unsigned long) nbyte);
  1841.     (void) fflush(stderr);
  1842.     ret = read(fildes, buf, nbyte);
  1843.     err = errno;
  1844.     (void) fprintf(stderr, "exiting read with %ld", (long) ret);
  1845.     if (ret == (ssize_t) -1)
  1846.         (void) fprintf(stderr, "; errno: %d", err);
  1847.     (void) fprintf(stderr, "\n");
  1848.     (void) fflush(stderr);
  1849.     return ret;
  1850. }
  1851.  
  1852. ssize_t posix_debug_write (int fildes, const void *buf, size_t nbyte)
  1853. {
  1854.     ssize_t ret;
  1855.     int err;
  1856.  
  1857.     (void) fprintf(stderr, "entering write(%d, %p, %lu)\n", fildes, buf, (unsigned long) nbyte);
  1858.     (void) fflush(stderr);
  1859.     ret = write(fildes, buf, nbyte);
  1860.     err = errno;
  1861.     (void) fprintf(stderr, "exiting write with %ld", (long) ret);
  1862.     if (ret == (ssize_t) -1)
  1863.         (void) fprintf(stderr, "; errno: %d", err);
  1864.     (void) fprintf(stderr, "\n");
  1865.     (void) fflush(stderr);
  1866.     return ret;
  1867. }
  1868.  
  1869. int posix_debug_fcntl (int fildes, int cmd, ...)
  1870. {
  1871.     va_list va;
  1872.     int ret, err, iarg;
  1873.     struct flock *farg;
  1874.  
  1875.     va_start(va, cmd);
  1876.     (void) fprintf(stderr, "entering fcntl(%d, %s", fildes, cmd_string(cmd));
  1877.     if (cmd == F_DUPFD || cmd == F_SETFD || cmd == F_SETFL)
  1878.     {
  1879.         iarg = va_arg(va, int);
  1880.         (void) fprintf(stderr, ", %d", iarg);
  1881.     }
  1882.     else if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW)
  1883.     {
  1884.         farg = va_arg(va, struct flock *);
  1885.         (void) fprintf(stderr, ", %p", farg);
  1886.     }
  1887.     va_end(va);
  1888.     (void) fprintf(stderr, ")\n");
  1889.     (void) fflush(stderr);
  1890.     if (cmd == F_DUPFD || cmd == F_SETFD || cmd == F_SETFL)
  1891.         ret = fcntl(fildes, cmd, iarg);
  1892.     else if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW)
  1893.         ret = fcntl(fildes, cmd, farg);
  1894.     else
  1895.         ret = fcntl(fildes, cmd);
  1896.     err = errno;
  1897.     (void) fprintf(stderr, "exiting fcntl with %d", ret);
  1898.     if (ret == -1)
  1899.         (void) fprintf(stderr, "; errno: %d", err);
  1900.     (void) fprintf(stderr, "\n");
  1901.     (void) fflush(stderr);
  1902.     return ret;
  1903. }
  1904.  
  1905. off_t posix_debug_lseek (int fildes, off_t offset, int whence)
  1906. {
  1907.     off_t ret;
  1908.     int err;
  1909.  
  1910.     (void) fprintf(stderr, "entering lseek(%d, %ld, %s)\n", fildes, (long) offset, whence_string(whence));
  1911.     (void) fflush(stderr);
  1912.     ret = lseek(fildes, offset, whence);
  1913.     err = errno;
  1914.     (void) fprintf(stderr, "exiting lseek with %ld", (long) ret);
  1915.     if (ret == (off_t) -1)
  1916.         (void) fprintf(stderr, "; errno: %d", err);
  1917.     (void) fprintf(stderr, "\n");
  1918.     (void) fflush(stderr);
  1919.     return ret;
  1920. }
  1921.  
  1922. /* Section 7: Device- and Class-Specific Functions */
  1923.  
  1924. speed_t posix_debug_cfgetospeed (const struct termios *termios_p)
  1925. {
  1926.     speed_t ret;
  1927.     int err, saved_errno;
  1928.  
  1929.     (void) fprintf(stderr, "entering cfgetospeed(%p)\n", termios_p);
  1930.     (void) fflush(stderr);
  1931.     saved_errno = errno;
  1932.     ret = cfgetospeed(termios_p);
  1933.     err = errno;
  1934.     (void) fprintf(stderr, "exiting cfgetospeed with %s", speed_string(ret));
  1935.     if (saved_errno != err)
  1936.         (void) fprintf(stderr, "; errno: %d", err);
  1937.     (void) fprintf(stderr, "\n");
  1938.     (void) fflush(stderr);
  1939.     return ret;
  1940. }
  1941.  
  1942. int posix_debug_cfsetospeed (struct termios *termios_p, speed_t speed)
  1943. {
  1944.     int ret, err;
  1945.  
  1946.     (void) fprintf(stderr, "entering cfsetospeed(%p, %s)\n", termios_p, speed_string(speed));
  1947.     (void) fflush(stderr);
  1948.     ret = cfsetospeed(termios_p, speed);
  1949.     err = errno;
  1950.     (void) fprintf(stderr, "exiting cfsetospeed with %d", ret);
  1951.     if (ret == -1)
  1952.         (void) fprintf(stderr, "; errno: %d", err);
  1953.     (void) fprintf(stderr, "\n");
  1954.     (void) fflush(stderr);
  1955.     return ret;
  1956. }
  1957.  
  1958. speed_t posix_debug_cfgetispeed (const struct termios *termios_p)
  1959. {
  1960.     speed_t ret;
  1961.     int err, saved_errno;
  1962.  
  1963.     (void) fprintf(stderr, "entering cfgetispeed(%p)\n", termios_p);
  1964.     (void) fflush(stderr);
  1965.     saved_errno = errno;
  1966.     ret = cfgetispeed(termios_p);
  1967.     err = errno;
  1968.     (void) fprintf(stderr, "exiting cfgetispeed with %s", speed_string(ret));
  1969.     if (saved_errno != err)
  1970.         (void) fprintf(stderr, "; errno: %d", err);
  1971.     (void) fprintf(stderr, "\n");
  1972.     (void) fflush(stderr);
  1973.     return ret;
  1974. }
  1975.  
  1976. int posix_debug_cfsetispeed (struct termios *termios_p, speed_t speed)
  1977. {
  1978.     int ret, err;
  1979.  
  1980.     (void) fprintf(stderr, "entering cfsetispeed(%p, %s)\n", termios_p, speed_string(speed));
  1981.     (void) fflush(stderr);
  1982.     ret = cfsetispeed(termios_p, speed);
  1983.     err = errno;
  1984.     (void) fprintf(stderr, "exiting cfsetispeed with %d", ret);
  1985.     if (ret == -1)
  1986.         (void) fprintf(stderr, "; errno: %d", err);
  1987.     (void) fprintf(stderr, "\n");
  1988.     (void) fflush(stderr);
  1989.     return ret;
  1990. }
  1991.  
  1992. int posix_debug_tcgetattr (int fildes, struct termios *termios_p)
  1993. {
  1994.     int ret, err;
  1995.  
  1996.     (void) fprintf(stderr, "entering tcgetattr(%d, %p)\n", fildes, termios_p);
  1997.     (void) fflush(stderr);
  1998.     ret = tcgetattr(fildes, termios_p);
  1999.     err = errno;
  2000.     (void) fprintf(stderr, "exiting tcgetattr with %d", ret);
  2001.     if (ret == -1)
  2002.         (void) fprintf(stderr, "; errno: %d", err);
  2003.     (void) fprintf(stderr, "\n");
  2004.     (void) fflush(stderr);
  2005.     return ret;
  2006. }
  2007.  
  2008. int posix_debug_tcsetattr (int fildes, int optional_actions, const struct termios *termios_p)
  2009. {
  2010.     int ret, err;
  2011.  
  2012.     (void) fprintf(stderr, "entering tcsetattr(%d, %s, %p)\n", fildes, optact_string(optional_actions), termios_p);
  2013.     (void) fflush(stderr);
  2014.     ret = tcsetattr(fildes, optional_actions, termios_p);
  2015.     err = errno;
  2016.     (void) fprintf(stderr, "exiting tcsetattr with %d", ret);
  2017.     if (ret == -1)
  2018.         (void) fprintf(stderr, "; errno: %d", err);
  2019.     (void) fprintf(stderr, "\n");
  2020.     (void) fflush(stderr);
  2021.     return ret;
  2022. }
  2023.  
  2024. int posix_debug_tcsendbreak (int fildes, int duration)
  2025. {
  2026.     int ret, err;
  2027.  
  2028.     (void) fprintf(stderr, "entering tcsendbreak(%d, %d)\n", fildes, duration);
  2029.     (void) fflush(stderr);
  2030.     ret = tcsendbreak(fildes, duration);
  2031.     err = errno;
  2032.     (void) fprintf(stderr, "exiting tcsendbreak with %d", ret);
  2033.     if (ret == -1)
  2034.         (void) fprintf(stderr, "; errno: %d", err);
  2035.     (void) fprintf(stderr, "\n");
  2036.     (void) fflush(stderr);
  2037.     return ret;
  2038. }
  2039.  
  2040. int posix_debug_tcdrain (int fildes)
  2041. {
  2042.     int ret, err;
  2043.  
  2044.     (void) fprintf(stderr, "entering tcdrain(%d)\n", fildes);
  2045.     (void) fflush(stderr);
  2046.     ret = tcdrain(fildes);
  2047.     err = errno;
  2048.     (void) fprintf(stderr, "exiting tcdrain with %d", ret);
  2049.     if (ret == -1)
  2050.         (void) fprintf(stderr, "; errno: %d", err);
  2051.     (void) fprintf(stderr, "\n");
  2052.     (void) fflush(stderr);
  2053.     return ret;
  2054. }
  2055.  
  2056. int posix_debug_tcflush (int fildes, int queue_selector)
  2057. {
  2058.     int ret, err;
  2059.  
  2060.     (void) fprintf(stderr, "entering tcflush(%d, %s)\n", fildes, queue_string(queue_selector));
  2061.     (void) fflush(stderr);
  2062.     ret = tcflush(fildes, queue_selector);
  2063.     err = errno;
  2064.     (void) fprintf(stderr, "exiting tcflush with %d", ret);
  2065.     if (ret == -1)
  2066.         (void) fprintf(stderr, "; errno: %d", err);
  2067.     (void) fprintf(stderr, "\n");
  2068.     (void) fflush(stderr);
  2069.     return ret;
  2070. }
  2071.  
  2072. int posix_debug_tcflow (int fildes, int action)
  2073. {
  2074.     int ret, err;
  2075.  
  2076.     (void) fprintf(stderr, "entering tcflow(%d, %s)\n", fildes, action_string(action));
  2077.     (void) fflush(stderr);
  2078.     ret = tcflow(fildes, action);
  2079.     err = errno;
  2080.     (void) fprintf(stderr, "exiting tcflow with %d", ret);
  2081.     if (ret == -1)
  2082.         (void) fprintf(stderr, "; errno: %d", err);
  2083.     (void) fprintf(stderr, "\n");
  2084.     (void) fflush(stderr);
  2085.     return ret;
  2086. }
  2087.  
  2088. pid_t posix_debug_tcgetpgrp (int fildes)
  2089. {
  2090.     pid_t ret;
  2091.     int err;
  2092.  
  2093.     (void) fprintf(stderr, "entering tcgetpgrp(%d)\n", fildes);
  2094.     (void) fflush(stderr);
  2095.     ret = tcgetpgrp(fildes);
  2096.     err = errno;
  2097.     (void) fprintf(stderr, "exiting tcgetpgrp with %ld", (long) ret);
  2098.     if (ret == (pid_t) -1)
  2099.         (void) fprintf(stderr, "; errno: %d", err);
  2100.     (void) fprintf(stderr, "\n");
  2101.     (void) fflush(stderr);
  2102.     return ret;
  2103. }
  2104.  
  2105. int posix_debug_tcsetpgrp (int fildes, pid_t pgrp_id)
  2106. {
  2107.     int ret, err;
  2108.  
  2109.     (void) fprintf(stderr, "entering tcsetpgrp(%d, %ld)\n", fildes, (long) pgrp_id);
  2110.     (void) fflush(stderr);
  2111.     ret = tcsetpgrp(fildes, pgrp_id);
  2112.     err = errno;
  2113.     (void) fprintf(stderr, "exiting tcsetpgrp with %d", ret);
  2114.     if (ret == -1)
  2115.         (void) fprintf(stderr, "; errno: %d", err);
  2116.     (void) fprintf(stderr, "\n");
  2117.     (void) fflush(stderr);
  2118.     return ret;
  2119. }
  2120.  
  2121. /* Section 8.2: C Language Input/Output Functions */
  2122.  
  2123. int posix_debug_fileno (FILE *stream)
  2124. {
  2125.     int ret, err;
  2126.  
  2127.     (void) fprintf(stderr, "entering fileno(%p)\n", stream);
  2128.     (void) fflush(stderr);
  2129.     ret = fileno(stream);
  2130.     err = errno;
  2131.     (void) fprintf(stderr, "exiting fileno with %d", ret);
  2132.     if (ret == -1)
  2133.         (void) fprintf(stderr, "; errno: %d", err);
  2134.     (void) fprintf(stderr, "\n");
  2135.     (void) fflush(stderr);
  2136.     return ret;
  2137. }
  2138.  
  2139. FILE *posix_debug_fdopen (int fildes, const char *type)
  2140. {
  2141.     FILE *ret;
  2142.     int err;
  2143.  
  2144.     (void) fprintf(stderr, "entering fdopen(%d, %s)\n", fildes, canonical_string(type));
  2145.     (void) fflush(stderr);
  2146.     ret = fdopen(fildes, type);
  2147.     err = errno;
  2148.     (void) fprintf(stderr, "exiting fdopen with %p", ret);
  2149.     if (ret == NULL)
  2150.         (void) fprintf(stderr, "; errno: %d", err);
  2151.     (void) fprintf(stderr, "\n");
  2152.     (void) fflush(stderr);
  2153.     return ret;
  2154. }
  2155.  
  2156. /* Section 8.3: Other C Language Functions */
  2157.  
  2158. void posix_debug_siglongjmp (sigjmp_buf env, int val)
  2159. {
  2160.     int err, saved_errno;
  2161.  
  2162.     (void) fprintf(stderr, "entering siglongjmp(%p, %d)\n", env, val);
  2163.     (void) fflush(stderr);
  2164.     saved_errno = errno;
  2165.     siglongjmp(env, val);
  2166.     err = errno;
  2167.     (void) fprintf(stderr, "exiting siglongjmp");
  2168.     if (saved_errno != err)
  2169.         (void) fprintf(stderr, "; errno: %d\n", err);
  2170.     (void) fprintf(stderr, "\n");
  2171.     (void) fflush(stderr);
  2172. }
  2173.  
  2174. void posix_debug_tzset (void)
  2175. {
  2176.     int err, saved_errno;
  2177.  
  2178.     (void) fprintf(stderr, "entering tzset()\n");
  2179.     (void) fflush(stderr);
  2180.     saved_errno = errno;
  2181.     tzset();
  2182.     err = errno;
  2183.     (void) fprintf(stderr, "exiting tzset");
  2184.     if (saved_errno != err)
  2185.         (void) fprintf(stderr, "; errno: %d\n", err);
  2186.     (void) fprintf(stderr, "\n");
  2187.     (void) fflush(stderr);
  2188. }
  2189.  
  2190. /* Section 9: System Databases */
  2191.  
  2192. struct group *posix_debug_getgrgid (gid_t gid)
  2193. {
  2194.     struct group *ret;
  2195.     int err;
  2196.  
  2197.     (void) fprintf(stderr, "entering getgrgid(%lu)\n", (unsigned long) gid);
  2198.     (void) fflush(stderr);
  2199.     ret = getgrgid(gid);
  2200.     err = errno;
  2201.     (void) fprintf(stderr, "exiting getgrgid with %p", ret);
  2202.     if (ret == NULL)
  2203.         (void) fprintf(stderr, "; errno: %d", err);
  2204.     (void) fprintf(stderr, "\n");
  2205.     (void) fflush(stderr);
  2206.     return ret;
  2207. }
  2208.  
  2209. struct group *posix_debug_getgrnam (const char *name)
  2210. {
  2211.     struct group *ret;
  2212.     int err;
  2213.  
  2214.     (void) fprintf(stderr, "entering getgrnam(%s)\n", canonical_string(name));
  2215.     (void) fflush(stderr);
  2216.     ret = getgrnam(name);
  2217.     err = errno;
  2218.     (void) fprintf(stderr, "exiting getgrnam with %p", ret);
  2219.     if (ret == NULL)
  2220.         (void) fprintf(stderr, "; errno: %d", err);
  2221.     (void) fprintf(stderr, "\n");
  2222.     (void) fflush(stderr);
  2223.     return ret;
  2224. }
  2225.  
  2226. struct passwd *posix_debug_getpwuid (uid_t uid)
  2227. {
  2228.     struct passwd *ret;
  2229.     int err;
  2230.  
  2231.     (void) fprintf(stderr, "entering getpwuid(%lu)\n", (unsigned long) uid);
  2232.     (void) fflush(stderr);
  2233.     ret = getpwuid(uid);
  2234.     err = errno;
  2235.     (void) fprintf(stderr, "exiting getpwuid with %p", ret);
  2236.     if (ret == NULL)
  2237.         (void) fprintf(stderr, "; errno: %d", err);
  2238.     (void) fprintf(stderr, "\n");
  2239.     (void) fflush(stderr);
  2240.     return ret;
  2241. }
  2242.  
  2243. struct passwd *posix_debug_getpwnam (const char *name)
  2244. {
  2245.     struct passwd *ret;
  2246.     int err;
  2247.  
  2248.     (void) fprintf(stderr, "entering getpwnam(%s)\n", canonical_string(name));
  2249.     (void) fflush(stderr);
  2250.     ret = getpwnam(name);
  2251.     err = errno;
  2252.     (void) fprintf(stderr, "exiting getpwnam with %p", ret);
  2253.     if (ret == NULL)
  2254.         (void) fprintf(stderr, "; errno: %d", err);
  2255.     (void) fprintf(stderr, "\n");
  2256.     (void) fflush(stderr);
  2257.     return ret;
  2258. }
  2259.